<?php
namespace app\common\model;

use think\Model;

/**  YSF
 *   常见问题 模型
 *   Date: 2019/3/5
 * Class CommonProblemModel
 * @package app\common\model
 */
class CommonProblemModel extends Model
{
    // 表名
    protected $name = 'common_problem';

    // 连表列表查询
    public function getJoinAll($where=[],$join=[],$field='*',$page=1,$pageSize=999,$order='')
    {
        $result = $this->alias('a')
                    ->where($where)
                    ->join($join)
                    ->field($field)
                    ->page($page, $pageSize)
                    ->order($order)
                    ->select();
        return $result;
    }

    // 连表数量查询
    public function getJoinCount($where=[],$join=[])
    {
        $result = $this->alias('a')
                    ->where($where)
                    ->join($join)
                    ->count();
        return $result;
    }

    // 连表单条查询
    public function getJoinOne($where=[],$join=[],$field='*')
    {
        $result = $this->alias('a')
                    ->where($where)
                    ->join($join)
                    ->field($field)
                    ->find();
        return $result;
    }

    // 单表单条查询
    public function getOne($where=[],$field='*')
    {
        $result = $this->where($where)->field($field)->find();
        return $result;
    }

    // 添加操作
    public function add($data=[])
    {
        $result = $this->allowField(true)->insertGetId($data);
        return $result;
    }

    // 编辑操作
    public function edit($where=[],$data=[])
    {
        $result = $this->where($where)->update($data);
        return $result;
    }

    // 删除操作
    public function delete($where=[])
    {
        $result = $this->where($where)->delete();
        return $result;
    }











}